<template>
  <!-- 账单 -->
  <div class="Check">
    <div class="body">
      <div class="g-con">
        <div class="main">
          <div class="title">{{ t('userCenter.t6') }}</div>

          <el-tabs
            v-model="activeName"
            type="card"
            class="mt-2"
            @tab-change="tabChange"
          >
            <el-tab-pane
              :label="item.label"
              :name="item.name"
              :key="item.name"
              v-for="item in tabsData"
            >
            </el-tab-pane>
          </el-tabs>

          <div class="search flexsc">
            <div class="item">
              <el-input
                v-model="searchData.orderNo"
                :placeholder="t('invitationQuotation.p1')"
              />
            </div>
            <el-button
              type="primary"
              @click="handleSearch"
            >
              {{ t('invitationQuotation.b1') }}
            </el-button>
            <el-button
              type="primary"
              color="#252628"
              @click="handleReset"
            >
              {{ t('invitationQuotation.b2') }}
            </el-button>
          </div>

          <div class="g-order-list">
            <div
              class="li mt-2"
              v-for="item in listData"
              :key="item.id"
            >
              <div class="attr">
                <!-- <div class="item">
                  <span>账单编号:</span>
                  <span></span>
                </div>
                <div class="item"></div> -->
                <div class="item">
                  <span>{{ t('invitationQuotation.attr1') }}:</span>
                  <span>{{ item.dockOrderNo }}</span>
                </div>
                <div class="item">
                  <span>{{ t('invitationQuotation.attr2') }}:</span>
                  <span>{{ item.dockOrderName }}</span>
                </div>
                <div class="item">
                  <span>{{ t('userCenter.cattr1') }}:</span>
                  <span>{{ item.quoteEnterpris }}</span>
                </div>
                <div class="item">
                  <span>{{ t('userCenter.cattr2') }}:</span>
                  <span>{{ item.updateByName }}</span>
                </div>
                <div class="item">
                  <span>{{ t('userCenter.cattr3') }}:</span>
                  <span v-if="locale === 'zh-CN'">共 {{ item.detailCount }} 项</span>
                  <span v-if="locale === 'en'">{{ item.detailCount }} items in total</span>
                </div>
                <div class="item">
                  <span>{{ t('userCenter.cattr4') }}:</span>
                  <span>{{ item.detailAmount }} {{ getDictLabel('currency', item.payCurrency) }}</span>
                </div>
              </div>

              <div class="bottom flexsb mt-3">
                <div class="">
                  <el-button
                    type="primary"
                    @click="open(item)"
                  >
                    {{ t('invitationQuotation.b3') }}
                  </el-button>
                </div>
              </div>
            </div>
          </div>

          <div class="flexcc mt-3">
            <el-pagination
              layout="prev, pager, next"
              :hide-on-single-page="total <= page.pageSize"
              :total="total"
              v-model:current-page="page.pageNum"
              :page-size="page.pageSize"
              @current-change="handleCurrentChange"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onBeforeMount, watch, nextTick, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { dateFormat } from '@/utils/index'
import useLogin from '@/stores/login'
import { receivedFinishOrderApi } from '@/service/dockOrder'
import useDict from '@/hooks/useDict'

const { dictData, getDictData, getDictLabel } = useDict()

const router = useRouter()
const route = useRoute()

const store = useLogin()

const { t, locale } = useI18n()
watch(locale, () => {
  init()
})

onBeforeMount(() => {
  init()
})

// tab
const tabsData = ref([])
const setTabsData = () => {
  const arr = [
    {
      label: t('userCenter.l1'),
      name: '0',
      role: ['05', '06'] // 船东/船管
    },
    {
      label: t('userCenter.l2'),
      name: '1',
      role: ['07'] // 船东/船管/修船厂
    }
  ]

  tabsData.value = arr.filter((item) => item.role.includes(store.userInfo.customerClassCode))
  activeName.value = tabsData.value[0].name
}
const activeName = ref('')
const tabChange = (value) => {
  page.value.pageNum = 1
  searchData.value = {}
  listData.value = []
  getList()
}

// 查询
const searchData = ref({})
const shipOptions = ref([])
const handleSearch = () => {
  page.value.pageNum = 1
  if (searchData.value.shipId) {
    searchData.value.shipList = [searchData.value.shipId]
  }
  getList()
}
const handleReset = () => {
  page.value.pageNum = 1
  searchData.value = {}
  getList()
}

// 坞修单列表
const listData = ref([])
const page = ref({
  pageNum: 1, // 当前页码
  pageSize: 6 // 每页条数
})
const total = ref(0) // 总数
const getList = () => {
  receivedFinishOrderApi(page.value, searchData.value).then(({ data, total: t }) => {
    listData.value = data
    total.value = t
  })
}
// 分页
const handleCurrentChange = (val) => {
  getList()
}

// 查看
const open = (item, path) => {
  const url = router.resolve({
    path: '/user/checkDetail',
    query: {
      id: item.id
    }
  })
  window.open(url.href)
}

//
const init = async () => {
  getDictData('currency')
  setTabsData()
  getList()
}
</script>

<style scoped lang="scss">
.Check {
  .el-button {
    min-width: 140px;
  }
  .body {
    padding: 30px 0 70px;
    background: #f5f5f5;
    margin-bottom: -76px;

    .main {
      background: #fff;
      padding: 25px 35px;
      .title {
        border-bottom: 2px solid #212121;
        padding-bottom: 20px;
        text-transform: uppercase;
        font-weight: bold;
        font-size: 20px;
        color: var(--mainColor);
      }
      .search {
        margin-top: 25px;
        .item {
          width: 200px;
          margin-right: 20px;
        }
      }
    }
  }
}
</style>
